import {PureComponent, ReactNode} from "react";

interface IProps {
    name:string,
    age?:number
}

interface IState {
    message:string,
    counter:number
}

interface ISnapshot {
    address:string
}

class Demo02 extends PureComponent<IProps,IState,ISnapshot>{
    name = "aaaaa";
    state = {
        message:"hello,react",
        counter:99
    }
    // constructor(props:IProps){
    //     super(props);
    //     this.state = {
    //         message:"hello,react",
    //         counter:100
    //     }
    // };

    getSnapshotBeforeUpdate(prevProps:IProps,prevState:IState){
        console.log(111)
        return {
            address:"江苏省南京市",
            name:"Qilin"
        }
    }
    componentDidMount(){
        console.log("componentDidMount")
    }
    componentDidUpdate(){
        console.log("componentDidUpdate")
    }

    render(): ReactNode {
        return (
            <div>
                <div>name:{this.props.name}</div>
                <div>age:{this.props.age}</div>
                <div>message:{(this.state as any).message}</div>
                <div>counter:{(this.state as any).counter}</div>
                <div>message:{this.state.message}</div>
                <div>counter:{this.state.counter}</div>
            </div>
        )
    }
}

export default Demo02;
